 
{Copyright  2003 by Cioina Alexei. All rights reserved.}

MY DEFINITIONS 
 Domain is a closed set of planar points which satisfy a logical algebraic
 condition. 
 Primitive (atom) is the simplest domain. The following  primitives have been
 defined in TDomainsEval class:
  Closed Ellipse with rotation angle, 
  Closed Rectangle with rotation angle and 
  Closed Roundish Rectangle with rotation angle.
 Operations are 5 known  logical algebraic operations :
  Union, Intersection, Complement, Difference and Symmetrical  Difference. 
 
DESCRIPTION
 TDomainsEval class can parse and evaluate a composed domain built with
  primitives and operations.
 After parsing you can test planar points if they are included in the domain or
  every part of the domain.

SUPPORT 
 Delphi6, Delphi7, Kylix2, Kylix3, CBuilder6.

BUILT-IN FUNCTIONS
============================================================================================================
 TDomainsEval class contains all functions built-in TCioinaEval v7.4.0 class (See TCioinaEval).
 Following functions were added:

  FUNCTION 'ELLIP' SYNTAX ->Ellip(X0, Y0, Width, Height, Angle, Function) GIVES A ELLIPSE OBJECT WHEN X0,Y0- ELLIPSE ORIGIN, Width, Height - 2a, 2b ELLIPSE AXES
                             Angle- ROTATION ANGLE, Function - MATHEMATICAL EXPRESSION ASSOCIATED TO ELLIPSE OBJECT.
  FUNCTION 'RECT'  SYNTAX ->Rect(X0, Y0, Width, Height, Angle, Function) GIVES A RECTANGLE OBJECT WHEN X0,Y0- RECTANGLE ORIGIN, Width, Height - RECTANGLE WIDTH AND HEIGTH
                             Angle- ROTATION ANGLE, Function - MATHEMATICAL EXPRESSION ASSOCIATED TO RECTANGLE OBJECT.
  FUNCTION 'ROUND' SYNTAX ->Round(X0, Y0, Width, Height, Angle, Function) GIVES A ROUND RECTANGLE OBJECT WHEN X0,Y0- RECTANGLE ORIGIN, Width, Height - RECTANGLE WIDTH AND HEIGTH
                             Angle- ROTATION ANGLE, Function - MATHEMATICAL EXPRESSION ASSOCIATED TO RECTANGLE OBJECT.
  FUNCTION 'UNION' SYNTAX ->Union(A, B, [C]...) GIVES UNION BETWEEN A QUANTITY OF OBJECTS WHEN A, B, C OTHER UNIONS, INTERSECTIONS, DIFFERENCES OR ELLIPSES AND RECTANGLES OBJECTS.
  FUNCTION 'INTER' SYNTAX ->Inter(A,B,[C]...) GIVES INTERSECTION BETWEEN A QUANTITY OF OBJECTS WHEN A, B, C OTHER UNIONS, INTERSECTIONS, DIFFERENCES OR ELLIPSES AND RECTANGLES OBJECTS.
  FUNCTION 'DIFF'  SYNTAX ->Diff(A,B) GIVES DIFFERENCE BETWEEN OBJECTS WHEN A, B OTHER UNIONS, INTERSECTIONS, DIFFERENCES OR ELLIPSES AND RECTANGLES OBJECTS.
  FUNCTION 'SDIFF' SYNTAX ->SDiff(A,B) GIVES SYMMETRICAL DIFFERENCE BETWEEN OBJECTS WHEN A, B OTHER UNIONS, INTERSECTIONS, DIFFERENCES OR ELLIPSES AND RECTANGLES OBJECTS.
  FUNCTION 'SUPPL' SYNTAX ->Suppl(A) GIVES SUPPLEMENT OF OBJECT WHEN A MAY BE UNION, INTERSECTION, DIFFERENCE OR ELLIPSE AND RECTANGLE OBJECT.
   

TDOMAINSEVAL PUBLIC INTERFACE.
============================================================================================================
 TDomainsEval=class
  public
   OnVerifySyntaxSemanticsError:TNotifyEvent;
   OnDoDomainExpressionError:TNotifyEvent;
   function  DomGet(i:Integer):TDomRecord1;
   procedure DomGraphicImage(var a:TCoordVector;k: Integer; flag:Boolean);
   function  DomIsInterior(x,y:TReal;k :Integer):Integer;
   function  DomIdToPosition(i:Integer):Integer;
   property  DomLen:Integer               read DomCitesteLen;
   property  DomId[i:Integer]:Integer     read DomCitesteId;
   property  DomX0[i:Integer]:TReal       read DomCitesteX0 write DomPuneX0;
   property  DomY0[i:Integer]:TReal       read DomCitesteY0 write DomPuneY0;
   property  DomHeight[i:Integer]:TReal   read DomCitesteHeigth write DomPuneHeigth;
   property  DomWidth[i:Integer]:TReal    read DomCitesteWidth write DomPuneWidth;
   property  DomAngle[i:Integer]:TReal    read DomCitesteAngle write DomPuneAngle;
   property  DomFunc[i:Integer]:string    read DomCitesteFunc write DomPuneFunc;
   property  DomName[i:Integer]:Char      read DomCitesteNume write DomPuneNume;
   property  DomRoundish:TReal           read DomCitesteRotund write DomPuneRotund;
   property  DomImageWidth:TReal index 0  read DomCitesteImageWH write DomPuneImageWH;
   property  DomImageHeight:TReal index 1 read DomCitesteImageWH write DomPuneImageWH;
   property  DomCenterX:TReal index 0     read DomCitesteCenterXY write DomPuneCenterXY;
   property  DomCenterY:TReal index 1     read DomCitesteCenterXY write DomPuneCenterXY;
   property  DomMagnifying:TReal           read DomCitesteProportia write DomPuneProportia;
   property  DomEllipseStep:Integer read DomCitesteNumarPuncteElipsa
                                          write DomPuneNumarPuncteElipsa;
   property  DomRoundStep:Integer read DomCitesteNumarPuncteRotungit
                                          write DomPuneNumarPuncteRotungit;

   procedure ProgressForm(ExternForm:TProgressForm);
   function  DoDomainExpression(x,y:TReal):Integer;
   function  DoPartDomainExpression(i:Integer;x,y:TReal):Integer;
   function  IsValidIdentName(s:string):Boolean;
   procedure Clear;
   procedure VerifySyntaxSemantics(MathStr,VarStr:string);overload;
   procedure VerifySyntaxSemantics(MathStr:string);overload;
   procedure DeleteParantheses(var s:string);
   function  IsExistString(var s,ss:string):Boolean;

   function  ItemDependece(i:Integer):Integer;
   function  ItemByComand(i:Integer):Integer;
   function  ComandByItem(i,j:Integer):Integer;
   function  ComandCountByItem(i:Integer):Integer;
   function  ListByItem(i,j:Integer):Integer;
   function  ListCountByItem(i:Integer):Integer;
   function  StrByItem(i:Integer):string;
   function  StrByComand(i:Integer):string;
   procedure ModifyAtom(i:Integer;s1:string);
   function  ModifySubDomain(i:Integer;s:string):string;
   function  DomNameByItem(i:Integer):Integer;
   function  DomNameByComand(i:Integer):Integer;
   function  DomIdByComand(i:Integer):Integer;
   function  DomIdByItem(i:Integer):Integer;

   property  TreeNodeCount:Integer               read fTreeNodeCount;
   property  VariableLowIndex:Integer            read fVariableLowIndex;
   property  VariableCount:Integer               read VarCount;
   property  VariableName[i:Integer]:string      read ScoateNumeVar;
   property  DomainsExpressionString:string      read CitesteDomainsExpressionString;
   property  MathException: ShortInt             read ExceptionId;
   property  ErrorFlag:Boolean                   read ErrorMsg;
   property  AllocDynamicMemoryInfo:Cardinal read fDynamicMemoryInfo;
   property  ErrorMessageInfo:string             read ErrorMessage;
   property  BuiltInFunctionInfo[i:Byte]:string  read UsedFunc;
   property  ExceptionInfo[i:ShortInt]:string    read fExceptionInfo;
   property  OwnerInfo:string index 0            read CitesteInfo;
   property  VersionInfo:string index 1          read CitesteInfo;
   property  TypeInfo:string index 2             read CitesteInfo;

  constructor Create; overload;
  constructor Create(FuncArray:TUserFuncArray);overload;
  destructor  Destroy;override;
 end;

METHODS OVERVIEW
============================================================================================================
 constructor TDomainsEval.Create;overload: create an instance of TDomainsEval object without user defined functions
 constructor TDomainsEval.Create(FuncArray:TUserFuncArray);overload: create an instance of TDomainsEval object with user defined functions
============================================================================================================
 procedure  TDomainsEval.Free, 
 destructor TDomainsEval.Destroy;override: free an instance of TDomainsEval object.
============================================================================================================
 procedure TDomainsEval.VerifySyntaxSemantics(MathStr,VarStr:string);overload,
 procedure TDomainsEval.VerifySyntaxSemantics(MathStr:string);overload: parse a domain expression string
      
	Example:

ev1.VerifySyntaxSemantics(Ellip(Sin(2)+1/2,(1/2)^2.4,1/4,1/3,pi/3,sin(x)+y^2),x,y);


TDomainsEval.VerifySyntaxSemantics(MathStr:string) automatic check variables in MathStr string.

	Example:

procedure TForm1.Button1Click(Sender: TObject);
var i:Integer;
    s:string;
begin
 s:='';
 ev1.VerifySyntaxSemantics(Edit1.Text);
 for i:=ev1.VariableLowIndex to ev1.VariableCount do s:=s+ev1.VariableName[i]+',';
 if not(ev1.ErrorFlag)then ShowMessage('Math expression was parsed and the following variables: '+s +' were found');
end;
============================================================================================================
 function TDomainsEval.DoDomainExpression(x,y:TReal):Integer: tests a planar point;
 if DoDomainExpression(x,y)=1 -> point (x,y) is in interior of domain; 
 if DoDomainExpression(x,y)=0 -> point (x,y) is on frontier of domain; 
 if DoDomainExpression(x,y)=-1 -> point (x,y) is outside of domain; 
============================================================================================================
 function TDomainsEval.DoPartDomainExpression(i:Integer;x,y:TReal):Integer: tests a planar point;
 i is Id of partial domain;
 if DoPartDomainExpression(i,x,y)=1 -> point (x,y) is in interior of partial domain; 
 if DoPartDomainExpression(i,x,y)=0 -> point (x,y) is on frontier of partial domain; 
 if DoPartDomainExpression(i,x,y)=-1 -> point (x,y) is outside of partial domain; 
============================================================================================================
SAMPLES OF DOMAIN EXPRESSION STRINGS
 
 ev1.VerifySyntaxSemantics(Inter(Rect(0,0,1,1,pi/12,1),Rect(0,0,1,1,0,1)),x,y);

 ev1.VerifySyntaxSemantics(Inter(Suppl(Ellip(0,0,1/2,1/4,pi/12,1)),Rect(0,0,1,1,0,1)),x,y);

 ev1.VerifySyntaxSemantics(Inter(Suppl(Union(Ellip(-0.19502350033179,-0.15501867975091,1/10,1/5,pi/3,0),
  Ellip(0.17502109004135,0.19002289775918,1/10,1/5,pi/3,0),Ellip(-0.18002169261396,0.20502470547701,1/10,1/5,(-pi)/3,0),
  Ellip(0.17002048746874,-0.1500180771783,1/10,1/5,(-pi)/3,0))),Round(0,0,1,1,0,1)),x,y);
